package com.fyl.schedule;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;

@DisallowConcurrentExecution
public class QuartzJobDisallowConcurrentExecution implements Job {

    private static final Logger log = LoggerFactory.getLogger(QuartzJobDisallowConcurrentExecution.class);

    @Override
    public void execute(JobExecutionContext context) {
        Object jobBean = context.getMergedJobDataMap().get("jobBean");
        Method method = (Method) context.getMergedJobDataMap().get("jobMethod");
        try {

            if (method.getParameterTypes().length > 0) {
                method.invoke(jobBean, context);
            } else {
                method.invoke(jobBean);
            }

        } catch (Exception e) {
            log.error("job method execute error:", e);
        }

    }
}
